import { Menu } from '@/api/model/menuModel';
import { request } from '@/utils/request';

import { RouteItem } from '../model/permissionModel';

export const MenuType = {
  MENU: '0',
  BUTTON: '1',
};

export const MENU_TYPES = [
  { label: '菜单', value: MenuType.MENU },
  { label: '按钮', value: MenuType.BUTTON },
];

export function getMenuList() {
  return request.get<RouteItem[]>({ url: '/upms/menu/getMenuList' });
}
/**
 * 查询单个的信息
 */
export function getMenuById(id?: string) {
  return request.get<Menu>({ url: `/upms/menu/${id}` });
}
/**
 *
 * @returns 树形结构的组织
 */
export function getAllMenuList() {
  return request.get<Menu[]>({ url: '/upms/menu/getAllMenuList' });
}

/**
 * 获取对应人员角色的权限点
 */
export function getRoleMenuIds(roleId?: string) {
  return request.get({ url: `/upms/menu/getRoleMenuIds/${roleId}` });
}

/**
 * 添加菜单
 */
export function addMenu(data: any) {
  return request.post({ url: '/menu', data });
}

/**
 * 修改菜单
 */
export function updateMenu(data: any) {
  return request.put({ url: '/menu', data });
}

/**
 * 删除菜单
 */
export function deleteMenu(id: string) {
  return request.delete({ url: `/menu/${id}` });
}
